<?php

namespace addons\shopro\job;

use app\admin\model\CatOrder;
use app\common\library\Sms as Smslib;
use baofu\Util\Log;
use think\queue\Job;
use think\Db;

/**
 * 短信自动操作
 */
class OrderSms extends BaseJob
{

    //将当前消息发给绑卡用户
    public function sending_sms(Job $job, $data)
    {
        Log::LogWirte('开始发送通知短信:');

        try {
            $order = $data['order'];

            Log::LogWirte('开始发送通知短信:'.$order['id']);

            // 重新查询订单
            $order = CatOrder::get($order['id']);
            //订单存在并且已经签约
            if ($order && in_array($order['status'],[1,2,4]) && $order['remaining_cycle'] != 0) {

                //获取当前签约订单的绑卡手机号
                $mobile = Db::name('user_baofu_bank')->where('protocol_no',$order['protocol_no'])->value('phone');
                Smslib::notice($mobile, '', 'sending_1');

                Log::LogWirte('结束发送通知短信:'.$order['id']);
            }else{
                Log::LogWirte('结束发送通知短信');
            }

            // 删除 job
            $job->delete();
        } catch (\Exception $e) {
            // 队列执行失败
            Log::LogWirte('queue-' . get_class() . '-sending_sms' . '：执行失败，错误信息：' . $e->getMessage());
        }
    }
}